package Demo;

public class Demo7 {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
               System.out.println("线程开始!");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("线程结束!");
        });

        System.out.println(t.isAlive());
        // 线程还没被创建出来是false
        t.start();
        System.out.println(t.isAlive());
        // 线程创建出来了,但是还没有被销毁是true
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(t.isAlive());
        // t线程被销毁了是false
    }
}

/*
class Solution {
public:
    string reverseWords(string s) {
        string ans;
        int i = s.size() - 1;
        while(i >= 0)
        {
            int c = 0;
            while(i >= 0 && s[i] == ' ') i--;
            while(i >= 0 && s[i] != ' ')
            {
                i--;
                c++;
            }
            if(c)
            ans += s.substr(i+1,c) + " ";
        }

        return ans.substr(0,ans.size() - 1);
    }
};
*/


/*
class Solution
{
public:
    int lengthOfLongestSubstring(string s)
    {
        int n = s.size();
        int hash[128] = {0};
        // s 由英文字母、数字、符号和空格组成 ? 没仔细审题

        int ans = 0;
        for(int left = 0,right = 0;right < n;)
        {
            hash[s[right]]++;
            while(hash[s[right]] > 1)
            {
                hash[s[left]]--;
                left++;
            }
            ans = max(ans,right - left + 1);
            right++;
        }
        return ans;
    }
};
*/

/*
class Solution {
    public int maximum69Number (int num) {
        int max_base = 0;
        int base = 1;

        for(int i = num;i > 0;i /= 10){
            if(i % 10 == 6){
                max_base = base;
            }
            base *= 10;
        }

        return num + max_base * 3;
    }
}
*/

/*
class Solution {
public:
    int scoreOfString(string s) {
        int sum = 0;
        int n = s.size();
        for(int i = 1;i < n;i++){
            sum += abs(s[i] - s[i-1]);
        }

        return sum;
    }
};
*/


/*
class Solution {
public:
    double minimumAverage(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        vector<double> averages;
        int n = nums.size();

        for(int i = 0,j = n - 1;i < n / 2;i++,j--)
        {
            double k = (nums[i] + nums[j]) * 1.0 / 2;
            averages.push_back(k);
        }

        sort(averages.begin(),averages.end());

        return averages[0];
    }
};
*/

/*
class Solution {
public:
    int sumOfGoodNumbers(vector<int>& nums, int k) {
        // 2 1 0
        int sum = 0;
        int n = nums.size();
        for(int i = 0;i < n;i++)
        {
            if(i - k < 0 && i + k >= n)
            {
                continue;
            }
            else if(i < k && i + k < n && nums[i] > nums[i + k])
            {
                sum += nums[i];
            }else if(i >= k && i + k >= n && nums[i] > nums[i - k])
            {
                sum += nums[i];
            }else if(i >= k && i + k < n && nums[i] > nums[i - k] &&
            nums[i] > nums[i + k])
            {
                sum += nums[i];
            }
        }

        return sum;
    }
};
*/

/*
class Solution {
public:
    int countConsistentStrings(string allowed, vector<string>& words) {
        int hash[26] = {0};
        for(auto s : allowed)
        {
            hash[s - 'a']++;
        }

        int count = 0;
        for(auto x : words)
        {
            int n = x.size();
            int a = 1;
            for(int i = 0;i < n;i++)
            {
                if(hash[x[i] - 'a'])
                {
                    ;
                }else{
                    a = 0;
                    break;
                }
            }
            if(a)
            {
                count++;
            }
        }

        return count;
    }
};
*/

/*
class Solution
{
public:
    vector<int> findSubstring(string s, vector<string>& words)
    {
        vector<int> v;
        unordered_map<string,int> hash2;// 统计words字符串数组中字符串出现的次数
        for(const auto& ch : words) hash2[ch]++;

        int n = s.size();
        int len = words[0].size();
        for(int i = 0;i < len;++i)// 执行len次滑动窗口
        {
          unordered_map<string,int> hash1;// 统计窗口中子串出现的次数
          //这句不能放在循环外,哈希表每次要求是新的
          for(int left = i,right = i,count = 0;right + len <= n;right += len)
          {
            // 进窗口 + 维护count
            string in = s.substr(right,len);
            hash1[in]++;
            if(hash2.count(in)&&hash1[in] <= hash2[in]) count++;
            // hash2.count() 节省时间
            // 判断
            if(right - left + 1 > words.size()*len)
            {
            // 出窗口 + 维护count
            string out = s.substr(left,len);
            if(hash2.count(out)&&hash1[out] <= hash2[out]) count--;
            hash1[out]--;
            left += len;
            }
            // 更新结果
            if(count == words.size()) v.push_back(left);
          }
        }
        return v;
    }
};
*/